package com.hfy.kandian.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hfy.kandian.dao.command.BaseCommand;
import com.hfy.kandian.dao.representation.TagRepresentation;
import com.hfy.kandian.entity.Tag;
import com.hfy.kandian.mapper.TagMapper;
import com.hfy.kandian.service.TagService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author HAN XIAOYANG
 * @since 2020-12-30
 */
@Service
public class TagServiceImpl extends ServiceImpl<TagMapper, Tag> implements TagService {
    @Autowired
    private TagMapper tagMapper;


    @Override
    public int add(String tagName, String tagIntroduction) {
        return tagMapper.insert(new Tag().setTagName(tagName).setTagIntroduction(tagIntroduction));
    }

    @Override
    public IPage<TagRepresentation> all(BaseCommand baseCommand) {
        List<TagRepresentation> tagRepresentations = new ArrayList<>();
        IPage<Tag> tagIPage = new Page<>();
        return tagMapper.selectPage(tagIPage,null).convert(tag -> tag.convertToTagRepresentation());
    }


}
